//
//  ZJDynamicLickTableViewCell.m
//  LovingPartyBuilding
//
//  Created by ZJ on 2017/6/7.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJDynamicLickTableViewCell.h"


@interface ZJDynamicLickTableViewCell ()
/** huis 背景 */
@property (nonatomic, strong) UIView *bgView;
/** 小箭头 */
@property (nonatomic, strong) UIImageView *arrows;
/** 下划线 */
@property (nonatomic, strong) UILabel *underLine;
/** 内容label */
@property (nonatomic, strong) UILabel *contentLabel;
/** 内容label下划线 */
@property (nonatomic, strong) UILabel *contentUnderLine;
/** 心imageView */
@property (nonatomic, strong) UIImageView *loveImageView;
@end

@implementation ZJDynamicLickTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self.contentView addSubview:self.bgView];
        [self.contentView addSubview:self.arrows];
        [self.contentView addSubview:self.underLine];
        [self.contentView addSubview:self.contentLabel];
        [self.contentView addSubview:self.contentUnderLine];
        [self.contentLabel addSubview:self.loveImageView];
        
        self.arrows.sd_layout
        .topSpaceToView(self.contentView, 0)
        .leftSpaceToView(self.contentView, 80 * [UIScreen zj_screenWScale])
        .widthIs(50 * [UIScreen zj_screenWScale])
        .heightIs(10 * [UIScreen zj_screenHScale]);
        
        self.contentLabel.sd_layout
        .topSpaceToView(self.arrows, 5 *[UIScreen zj_screenHScale])
        .leftSpaceToView(self.contentView, (62 + 5) * [UIScreen zj_screenWScale])
        .widthIs([UIScreen zj_screenWith] - (62 + 12 + 10) * [UIScreen zj_screenWScale])
        .heightIs(20);
        
        self.bgView.sd_layout
        .topSpaceToView(self.arrows, 0)
        .leftSpaceToView(self.contentView, 62 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
        .heightIs(self.contentLabel.height + 10 * [UIScreen zj_screenHScale]);
        
        self.underLine.sd_layout
        .leftSpaceToView(self.contentView, 10 * [UIScreen zj_screenWScale])
        .rightSpaceToView(self.contentView, 10 * [UIScreen zj_screenWScale])
        .bottomSpaceToView(self.contentView, 0)
        .heightIs(1);
        
        self.contentUnderLine.sd_layout
        .bottomSpaceToView(self.contentView, 0)
        .leftEqualToView(self.bgView)
        .rightEqualToView(self.bgView)
        .heightIs(1);
        
        self.loveImageView.sd_layout
        .topSpaceToView(self.contentLabel, 0)
        .leftSpaceToView(self.contentLabel, 0)
        .widthIs([NSString heightWithTextFont:self.contentLabel.font])
        .heightEqualToWidth();
    }
    return self;
}




#pragma mark - Setter
- (void)setLikeArray:(NSArray<ZJLikeList *> *)likeArray{
    NSMutableString *contentLabelText = [NSMutableString string];
    [contentLabelText appendString:@"    "];
    for (int i = 0; i < likeArray.count; i ++) {
        ZJLikeList *model = likeArray[i];
        if (i == 0) {
            [contentLabelText appendString:model.UNAME];
        }else{
            [contentLabelText appendString:@"、"];
            [contentLabelText appendString:model.UNAME];
        }
    }
    
    self.contentLabel.text = contentLabelText;
    
    self.contentLabel.sd_layout
    .topSpaceToView(self.arrows, 5 *[UIScreen zj_screenHScale])
    .leftSpaceToView(self.contentView, (62 + 5) * [UIScreen zj_screenWScale])
    .widthIs([UIScreen zj_screenWith] - (62 + 12 + 10) * [UIScreen zj_screenWScale])
    .heightIs([self.contentLabel getLableSizeWithMaxWidth:self.contentLabel.width].height);
    [self.contentLabel updateLayout];
    
    self.bgView.sd_layout
    .topSpaceToView(self.arrows, 0)
    .leftSpaceToView(self.contentView, 62 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.contentView, 12 * [UIScreen zj_screenWScale])
    .heightIs(self.contentLabel.height + 10 * [UIScreen zj_screenHScale]);
    
    [self.bgView updateLayout];
    
    if (self.haveComment) {//有评论
        [self.bgView setRadius:4 * [UIScreen zj_screenWScale] byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight];
        self.underLine.hidden = YES;
        self.contentUnderLine.hidden = NO;
    }else{//没有评论
        [self.bgView setRadius:4 * [UIScreen zj_screenWScale] byRoundingCorners:UIRectCornerAllCorners];
        self.underLine.hidden = NO;
        self.contentUnderLine.hidden = YES;
    }
}

#pragma mark - Getters

- (UIImageView *)arrows{
    if (_arrows == nil){
        _arrows = [UIImageView new];
        _arrows.image = [UIImage imageNamed:@"chat_bg_sanjiao"];
        _arrows.contentMode = UIViewContentModeBottom;
    }
    return _arrows;
}

- (UIImageView *)loveImageView{
    if (_loveImageView == nil){
        _loveImageView = [UIImageView new];
        _loveImageView.image = [UIImage imageNamed:@"xing"];
        _loveImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _loveImageView;
}
- (UILabel *)contentLabel{
    if (_contentLabel == nil){
        _contentLabel = [UILabel new];
        _contentLabel.font = [UIFont subTitleTextFont];
        _contentLabel.textColor = [UIColor zj_colorWithHexString:@"646a8c"];
        _contentLabel.numberOfLines = 2;
        _contentLabel.lineSpace = 1;
        _contentLabel.characterSpace = 1;
    }
    return _contentLabel;
}

- (UILabel *)underLine{
    if (_underLine == nil){
        _underLine = [UILabel new];
        _underLine.backgroundColor = [UIColor zj_colorWithHexString:@"ececec"];
    }
    return _underLine;
}

- (UILabel *)contentUnderLine{
    if (_contentUnderLine == nil){
        _contentUnderLine = [UILabel new];
        _contentUnderLine.backgroundColor = [UIColor zj_colorWithHexString:@"dedede"];
    }
    return _contentUnderLine;
}

- (UIView *)bgView{
    if (_bgView == nil){
        _bgView = [UIView new];
        _bgView.backgroundColor = [UIColor zj_colorWithHexString:@"ececec"];
    }
    return _bgView;
}

@end
